module.exports = function ($scope, $modalInstance, $resource, toaster, obj, what, date2str){
    
	$scope.obj = {};
	$scope.what = what;
	
	if(what == 'edit') {
		$scope.obj = obj;
	} 

	//分类下拉
    $resource('/api/as/goc/infodiffusion/notypelist', {}, {}).save({}, function (res) {
        console.log(res);

        if (res.errcode !== 0) {
            toaster.error({title: '', body: res.errmsg});
            return;
        }

        $scope.category = res.data;

    });

    //保存
	$scope.save = function() {
		if(!checkInfo($scope.obj)) return;
		$resource('/api/as/goc/infodiffusion/createinforeply', {}, {}).save($scope.obj, function(res){
            if (res.errcode === 0) {
                toaster.success({title: '', body: '保存成功'});
                $modalInstance.close();
            } else {
                toaster.error({title: '', body: res.errmsg});
            }
        });
	}
    
    //校验信息
	function checkInfo(obj){
		if(!obj.reply_title){
			toaster.warning({title: '', body: '请填写问题名称.'});
			return false;
		}
		if(!obj.reply_type_id){
			toaster.warning({title: '', body: '请填写问题类别.'});
			return false;
		}
		if(!obj.reply_title){
			toaster.warning({title: '', body: '请填写问题内容.'});
			return false;
		}
		return true;
	}
   
    //取消
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }

};